package com.way.filemanager.util;

import android.content.Context;
import android.net.ConnectivityManager;
import android.net.NetworkInfo;

public class ConnectionHelper {

    public static boolean hasNetwork(Context ctx){
        ConnectivityManager cManager=(ConnectivityManager)ctx.getSystemService(Context.CONNECTIVITY_SERVICE);
        NetworkInfo info = cManager.getActiveNetworkInfo();
          if (info != null && info.isAvailable()){

                return true;
          }else{

                return false;
          }
    }
    public static int getNetworkType(Context ctx){
        ConnectivityManager cManager=(ConnectivityManager)ctx.getSystemService(Context.CONNECTIVITY_SERVICE);
        NetworkInfo info = cManager.getActiveNetworkInfo();
          if (info != null && info.isAvailable()){
              if(info.getType() == ConnectivityManager.TYPE_WIFI){
                  return ConnectivityManager.TYPE_WIFI;
              }else{
                  return ConnectivityManager.TYPE_MOBILE;
              }
          }else{
                return -1;
          }
    }

}
